package cn.eyesea.cc.frame.processor.impl;

import cn.eyesea.cc.frame.factory.ProductionResourceFactory;
import com.google.common.collect.Lists;
import cn.eyesea.cc.frame.base.Assembly;
import cn.eyesea.cc.frame.base.ResultResource;
import cn.eyesea.cc.frame.context.AssemblyRealizeContext;
import cn.eyesea.cc.frame.context.CreateLogicalTypeCodeContext;
import cn.eyesea.cc.frame.factory.AssemblyFactory;
import cn.eyesea.cc.frame.processor.CreateLogicalTypeCodeProcessor;
import lombok.extern.slf4j.Slf4j;

/**
 * 业务类型默认实现类
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/7/12 11:08 下午
 */
@Slf4j
public class CreateLogicalTypeCodeProcessorDefaultImpl implements CreateLogicalTypeCodeProcessor {

    @Override
    public void process(CreateLogicalTypeCodeContext createLogicalTypeCodeContext) {

        // createLogicalTypeCodeContext
        //1、查询组件
        Assembly assembly = AssemblyFactory.getAssembly(createLogicalTypeCodeContext.getLogicalTypeEnum());
        if (null == assembly) {
            log.error("找不到对应的组件 LogicalType:{}", createLogicalTypeCodeContext.getLogicalTypeEnum());
        }

        //2、执行组件，获取结果资源
        AssemblyRealizeContext context = new AssemblyRealizeContext();
        context.setMainDomainInfo(createLogicalTypeCodeContext.getDomainInfo());
        context.setLogicalTypeEnum(createLogicalTypeCodeContext.getLogicalTypeEnum());
        context.setLogicalLayer(createLogicalTypeCodeContext.getLogicalLayerTypeEnum());
        context.setRelevantResultResources(Lists.newArrayList());
        context.setDomainConfig(createLogicalTypeCodeContext.getDomainConfig());
        context.setGlobalConfig(createLogicalTypeCodeContext.getGlobalConfig());

        ResultResource resultResource = assembly.realize(context);
        System.out.println(resultResource.getResourcePath());
        System.out.println(resultResource.getGenerateCode());

        //3、注册到生产资源库
        ProductionResourceFactory.registerProductionResource(resultResource);

    }


}
